<!--查询单车信息，并分页显示查询结果 -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="mybean.data.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.rowset.*" %>
<jsp:useBean id="loginBean" class="mybean.data.login" scope="session"/>
<jsp:useBean id="dataBean" class="mybean.data.DataByPage" scope="session"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>单车信息</title>
	<link rel="stylesheet" type="text/css" href="css/reset.css">
	<link rel="stylesheet" type="text/css" href="css/common.css">
	<link rel="stylesheet" type="text/css" href="css/index-2.css">
	<link rel="stylesheet" type="text/css" href="css/index-1.css">
</head>
<body>
	<%@ include file="Ahead.txt" %>
	<div class="Admin-content">			
		<center>		
		<!-- 分页显示查询结果 -->
		<jsp:setProperty name="dataBean" property="pageSize" param="pageSize"/><!-- 设置页大小和目前的页 -->
		<jsp:setProperty name="dataBean" property="currentPage" param="currentPage"/>
		<%
			request.setCharacterEncoding("utf-8");
			response.setContentType("utf-8");
			CachedRowSet rowset=dataBean.getRowSet();
				if(rowset== null){
					out.print("<h2>没有查询到相关信息</h2>");
					return;
				}
				else{
					String button1="",button2="";
					rowset.last();
					int totalRecord=rowset.getRow();
					if(totalRecord==0){
						out.print("<h2>没有查询到相关信息</h2>");
						return ;
					}
				%>
					</center>
		<center>
		<h3>当前显示的是单车信息</h3>
		<table>
			<tr style="background-color: #004b97;color: white">
				<th width=80 height=40>单车编号</th>
				<th width=100 height=40>地区</th>
				<th width=100 height=40>供应商</th>
				<th width=100 height=40>状态</th>
				<th width=70 height=40>管理人</th>
				<th width=120 height=40>价格（元/时）</th>
				<th width=80 height=40>租金</th>
				<th width=150 height=40>投入使用日期</th>
				<th width=100 height=40>操作</th>
			</tr>			
				<% 
				out.print("全部记录数"+totalRecord);//全部记录数
				int pageSize = dataBean.getPageSize();//每页显示的记录数
				int totalPages=dataBean.getTotalPages();
				if(totalRecord % pageSize==0)  totalPages=totalRecord/pageSize;//总页数
				else	totalPages=totalRecord/pageSize+1;
				dataBean.setPageSize(pageSize);
				dataBean.setTotalPages(totalPages);
				if(totalPages>=1){
					if(dataBean.getCurrentPage()<1)	dataBean.setCurrentPage(dataBean.getTotalPages());
					if(dataBean.getCurrentPage()>dataBean.getTotalPages())
						dataBean.setCurrentPage(1);
					int index = (dataBean.getCurrentPage()-1)*pageSize+1;
					rowset.absolute(index);//查询位置移动到currentPage页起始位置
					boolean boo=true;
					for(int i=1;i<=pageSize&&boo;i++){
						String number = rowset.getString("B_id");
						String district = rowset.getString("Dname");
						String provider = rowset.getString("Pname");
						String memo= rowset.getString("B_memo");
						String manager = rowset.getString("Mname");
						String price = rowset.getString("price");
						String deposit= rowset.getString("B_deposit");
						String date= rowset.getString("B_makedate");
						if(memo.equals("空闲")){
							button1 ="<form action='changeBike.jsp' method='post'>"+//把单车信息传过去，省得再从数据库中查
									"<input type='hidden'  name='number' value="+number+" >"+
									"<input type='hidden'  name='district' value="+district+" >"+
									"<input type='hidden'  name='provider' value="+provider+" >"+
									"<input type='hidden'  name='memo' value="+memo+" >"+
									"<input type='hidden'  name='manager' value="+manager+" >"+
									"<input type='hidden'  name='price' value="+price+" >"+
									"<input type='hidden'  name='deposit' value="+deposit+" >"+
									"<input type='hidden'  name='date' value="+date+" >"+
								"&nbsp;&nbsp;<input type='submit'  value='修改' class='submit'></form>";
							button2 ="<form id='bike' action='deleteBikeServlet' method='post'>"+
									"<input type='hidden'  name='number' value="+number+" >"+
											"<input type='hidden'  name='district' value="+district+" >"+
										"&nbsp;&nbsp;<input type='submit'  value='删除' class='submit'></form>";	
						}
						else {button1 = "";button2="已借出";}
						
							
			%>
			<tr style="background-color: #c0c0c0;">
				<td height=50><center><%=number %></center></td>
				<td height=50><center><%=district %><center></td>
				<td height=50><center><%=provider %><center></td>
				<td height=50><center><%=memo %></center></td>
				<td height=50><center><%=manager %></center></td>
				<td height=50><center><%=price %></center></td>
				<td height=50><center><%=deposit %></center></td>
				<td height=50><center><%=date %></center></td> 
				<td height=50><center><%=button1 %><%=button2 %></center></td> 
			</tr>
				<%		boo=rowset.next();
					}
				}
				}
			%>	
		</table>
		<%@ include file="bypage.txt" %>
		</center>				
    </div>	
	<!--页面底部-->
	<!--所以的页面底部都一样，用一个文本文件存储，所有JSP文件使用嵌入-->
	<%@ include file="footer.txt" %>
</body>
</html>